using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    public partial class Geo_AdministrativeDivisionComponent
    {

        /// <summary>
        /// Selects all records from the database table based on a foreign key.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public List<Geo_AdministrativeDivision> SelectAllWDivisionPostalAbbreviation(string DivisionPostalAbbreviation, string sortExpression)
        {
            List<Geo_AdministrativeDivision> listGeo_AdministrativeDivision = new List<Geo_AdministrativeDivision>();
            PlacementManager.DAL.Geo_AdministrativeDivision_DAL o = new PlacementManager.DAL.Geo_AdministrativeDivision_DAL();
            o.DivisionPostalAbbreviation = DivisionPostalAbbreviation;
            DataSet ds = o.SelectAllWDivisionPostalAbbreviation();
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listGeo_AdministrativeDivision.Add(new Geo_AdministrativeDivision((int)row["AdministrativeDivisionID"], (int)row["CountryID"], (string)row["DivisionName"], (string)row["DivisionPostalAbbreviation"]));
            }
            listGeo_AdministrativeDivision.Sort(new Geo_AdministrativeDivisionComparer(sortExpression));
            return listGeo_AdministrativeDivision;
        }

        /// <summary>
        /// Returns the identity of a state given the abbreviation
        /// </summary>
        /// <returns>AdminsitrativeDivisionId</returns>
        public int GetAdministrativeDivisionId(string DivisionPostalAbbreviation)
        {
            PlacementManager.DAL.Geo_AdministrativeDivision_DAL o = new PlacementManager.DAL.Geo_AdministrativeDivision_DAL();
            o.DivisionPostalAbbreviation = DivisionPostalAbbreviation;
            return o.GetAdministrativeDivisionIdWAbbreviation();
        }
    }
}
